/**
 *    Copyright (C) 2009 Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#ifndef CUBEFS_CORE_TOOLS_PLUGIN_HPP_
#define CUBEFS_CORE_TOOLS_PLUGIN_HPP_

#include <cubefs/api/types.hpp>
#include <cubefs/core/tools/file.hpp>
#include <cubefs/core/tools/configurator.hpp>
#include <cubefs/api/tools/library.hpp>
#include <cubefs/api/tools/version.hpp>
#include <vector>

namespace cubefs{ namespace tools {

using namespace cubefs::api;

struct Architecture{
	enum {X86_64, I386, ARM32};
};

struct OS {
	enum {POSIX, Windows, WinCE};
};

struct SystemDescriptor {
	Int arch_;
	Int os_;
};

SystemDescriptor GetSystemDescriptor();

struct ResourceDescriptor {
	Int arch_;
	bool plugin_;
};

class Plugin {
	Configurator config_;
	File path_;
	ResourceDescriptor descriptor_;
	SharedLibrary library_;
public:

	Plugin(const File& path);
	virtual ~Plugin() throw();

	Version GetVersion() const {
		return config_.GetProperty("version");
	}

	Version GetApiVersion() const {
		return config_.GetProperty("version.api");
	}

	Configurator& GetConfig() {
		return config_;
	}

	const Configurator& GetConfig() const {
		return config_;
	}

	String GetResourcePath() const {
		return path_.GetPath();
	}

	const ResourceDescriptor& GetResourceDescriptor() const {
		return descriptor_;
	}

	const SharedLibrary& GetLibrary() const {
		return library_;
	}

	SharedLibrary& GetLibrary() {
		return library_;
	}

	static Plugin* FindPlugin(const Configurator* config, StringRef type, StringRef, const Version& version, const Version& api_version);

protected:
	static ResourceDescriptor GetResouerceDescriptor(Configurator* config, const File& path);
};


}}

#endif
